<template>
  <div>
    <!-- 历史事件汇总 -->
    <flightLegHistory
      :report-handler="reportHandlerFH"
      @close="closeReportHandler"
    />

    <!-- 当前航段详情 -->
    <flightLegDetails
      @close="closeReportHandler"
    />

    <!-- ef报告 -->
    <efReport
      @close="closeReportHandler"
    />

    <!-- faultReport -->
    <faultReport
      @close="closeReportHandler"
    />
    <!-- 航段 -->
    <lefInfo
      @close="closeReportHandler"
    />
    <!-- 快照 -->
    <snapshot
      @close="closeReportHandler"
    />

    <!-- 报文上传 -->
    <messageUpload
      @close="closeReportHandler"
    />

    <!-- 事件详情 -->
    <eventDetails
      :report-handler="reportHandler2"
      :row-index="0"
      @close="closeReportHandler"
    />

    <!-- 航班信息 -->
    <airportInfo
      @close="closeReportHandler"
    />

    <!-- 统计详情 -->
    <faultDetails
      :report-handler="reportHandlerFH"
    />
    <!-- 事件历史详情 -->
    <faultDetails2
      :report-handler="reportHandlerFH"
    />

    <videoModal />
  </div>
</template>

<script>
import flightLegHistory from '@/pages/fraMonitoring/components/flightLegHistory';
import flightLegDetails from '@/pages/fraMonitoring/components/flightLegDetails';
import messageUpload from '@/pages/fraMonitoring/components/messageUpload';
import efReport from '@/pages/fraMonitoring/components/efReport';
import faultReport from '@/pages/fraMonitoring/components/faultReport';
import lefInfo from '@/pages/fraMonitoring/components/lefInfo';
import snapshot from '@/pages/fraMonitoring/components/snapshot';
import eventDetails from '@/pages/eventMonitoring/components/eventDetails';
import airportInfo from '@/pages/fraMonitoring/components/airportInfo';
import faultDetails from '@/pages/faultMonitoring/components/faultDetails';
import faultDetails2 from '@/pages/faultMonitoring/components/faultDetails2';
import videoModal from '@/pages/fraMonitoring/components/about/video.vue';
import { mapMutations } from 'vuex';
export default {
  components: {
    flightLegHistory,
    flightLegDetails,
    efReport,
    faultReport,
    lefInfo,
    snapshot,
    messageUpload,
    eventDetails,
    airportInfo,
    faultDetails,
    faultDetails2,
    videoModal
  },
  methods: {
    ...mapMutations('fraMonitoring', [
      'setState'
    ]),
    closeReportHandler(flag) {
      this.setState({ key: flag, payload: false });
    },
    // 把所有抽屉重置
    closeAllDrawersPopUp() {
      this.setState({ key: 'flightLegDetailsVisible', payload: false });
      this.setState({ key: 'legInfoVisible', payload: false });
      this.setState({ key: 'flightLegHistoryVisible', payload: false });
      this.setState({ key: 'efReportVisible', payload: false });
      this.setState({ key: 'faultReportVisible', payload: false });
      this.setState({ key: 'snapshotVisible', payload: false });
      this.setState({ key: 'messageUploadVisible', payload: false });
    },
    reportHandler2(e, record, flag, index, select = false) {
      e.stopPropagation();
      const currentRow = {
        ...record
      };
      if (this.$store.state.setting.openType !== '_blank') {
        this.closeAllDrawersPopUp();
      }
      localStorage.setItem('row', JSON.stringify(currentRow));

      if (flag === 'taskResearchVisible') {
        localStorage.setItem('trRow', JSON.stringify({ ...record }));
        this.setState({ key: 'eventDetailsVisible', payload: false });

        if (this.$store.state.setting.openType === '_self') {
          this.$router.push({ path: 'taskResearch', query: { m: '1' }});
        } else {
          const uuid = new Date().getTime();
          const routeData = this.$router.resolve({ path: 'taskResearch', query: { m: '1', uuid }});
          window.open(routeData.href, this.$store.state.setting.openType);
        }
      }
      this.setState({ key: flag, payload: true });
    },
    reportHandlerFH(record, flag) {
      localStorage.setItem('scRow', JSON.stringify({ ...record }));

      if (flag === 'taskResearchVisible') {
        localStorage.setItem('trRow', JSON.stringify({ ...record }));
        this.setState({ key: 'eventDetailsVisible', payload: false });
        if (this.$store.state.setting.openType !== '_blank') {
          this.closeAllDrawersPopUp();
        }
        // const modalList =
        // localStorage.getItem('showModal')
        //   ? JSON.parse(localStorage.getItem('showModal')) : [];

        // modalList.push('flightLegHistoryVisible');
        // localStorage.setItem('showModal', JSON.stringify(modalList));

        if (this.$store.state.setting.openType === '_self') {
          this.$router.push({ path: 'taskResearch', query: { m: '1' }});
        } else {
          const uuid = new Date().getTime();
          const routeData = this.$router.resolve({ path: 'taskResearch', query: { m: '1', uuid }});
          window.open(routeData.href, this.$store.state.setting.openType);
        }
      }
      this.setState({ key: flag, payload: true });
    }
  }
};
</script>

<style>

</style>
